package com.ggp.NettyLearn;

import java.net.InetAddress;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class HelloServerHandler extends SimpleChannelInboundHandler<String> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
		// 收到消息直接打印输出
		System.out.println(ctx.channel().remoteAddress() + "say: " + msg);
		
		ctx.writeAndFlush("Received your message !\n");
	}

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		System.out.println("RemoteAddress : " + ctx.channel().remoteAddress() + " active ! ");
		
		ctx.writeAndFlush("Welcome to " + InetAddress.getLocalHost().getHostName() + " service" + System.getProperty("line.separator"));
		
		super.channelActive(ctx);
	}
}
